package com.qd.admin.configurer;

import com.cdqidi.api.filter.SignParamFilter;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import javax.annotation.Resource;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author sjk
 * @create 2022-08-16 15:29
 * @since 1.0.0
 */
@ConditionalOnProperty(
        prefix = "sign.param",
        name = "enabled",
        havingValue = "true"
)
@Configuration
@Log
@RequiredArgsConstructor
public class FilterConfig {
    @Resource
    private SignParamFilter signParamFilter;

    @Bean
    public FilterRegistrationBean<SignParamFilter> servletRegistrationBean() {
        FilterRegistrationBean<SignParamFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(signParamFilter);
        bean.setName("signParamFilter");
        bean.addUrlPatterns("/api/*");
        bean.setOrder(Ordered.LOWEST_PRECEDENCE);
        return bean;
    }
}